define([
  'collections/Collection',
  'views/View',
  'views/List',
  'views/Item',
  'views/media/MediaViewer',
  'hbs!template/users/inbox/inbox-detail',
  'hbs!template/media/media-list'
], function(Collection, View, List, Item, MediaViewer, detail_template, media_list){
  var InboxMediaViewer = MediaViewer.extend({
    flags: {
      share: false,
      check: false,
      modal:true
    }
  });
  
  var MediaList = List.extend({
    template: media_list,
    itemView: InboxMediaViewer // The items will be MediaViewer type.
  });


  
  var InboxDetailView = View.extend({
    template: detail_template,

    events: {
      "click button[name=back]":        "back"    
    },
    
    initialize: function(options) {
      View.prototype.initialize.call(this, options);
      this.model.bind("change", this.initMediaContent, this);
    },

    initMediaContent: function() {
      this.mediaCollection = new Collection(this.model.get("contents"));
      this.mediaCollection.pagination.setLimit(2);

      this.render();
      
    },
    
    render: function() {
      View.prototype.render.call(this);
      if(this.mediaCollection) {
        var mediaList = new MediaList({el: "#media-files", collection: this.mediaCollection});
        mediaList.render();
      }
      return this;
    }
  });

  return InboxDetailView;
});